package com.weather.androidweather.model;

import android.os.Parcel;
import android.os.Parcelable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DayForecast implements Parcelable {
    private Date date;
    private String weather;
    private float maxTemp;
    private float minTemp;
    private int weatherIconRes;
    private String windDir;
    private String windScale;
    private int humidity;

    public DayForecast(String date, String weather, float minTemp, float maxTemp, 
                      int weatherIconRes, String windDir, String windScale, int humidity) {
        try {
            this.date = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(date);
        } catch (ParseException e) {
            this.date = null;
        }
        this.weather = weather;
        this.minTemp = minTemp;
        this.maxTemp = maxTemp;
        this.weatherIconRes = weatherIconRes;
        this.windDir = windDir;
        this.windScale = windScale;
        this.humidity = humidity;
    }

    protected DayForecast(Parcel in) {
        try {
            date = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(in.readString());
        } catch (ParseException e) {
            date = null;
        }
        weather = in.readString();
        minTemp = in.readFloat();
        maxTemp = in.readFloat();
        weatherIconRes = in.readInt();
        windDir = in.readString();
        windScale = in.readString();
        humidity = in.readInt();
    }

    public static final Creator<DayForecast> CREATOR = new Creator<DayForecast>() {
        @Override
        public DayForecast createFromParcel(Parcel in) {
            return new DayForecast(in);
        }

        @Override
        public DayForecast[] newArray(int size) {
            return new DayForecast[size];
        }
    };

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getWeather() {
        return weather;
    }

    public void setWeather(String weather) {
        this.weather = weather;
    }

    public float getMaxTemp() {
        return maxTemp;
    }

    public void setMaxTemp(float maxTemp) {
        this.maxTemp = maxTemp;
    }

    public float getMinTemp() {
        return minTemp;
    }

    public void setMinTemp(float minTemp) {
        this.minTemp = minTemp;
    }

    public int getWeatherIconRes() {
        return weatherIconRes;
    }

    public String getWindDir() {
        return windDir;
    }

    public String getWindScale() {
        return windScale;
    }

    public int getHumidity() {
        return humidity;
    }

    public String getFormattedDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("MM月dd日 E", Locale.CHINA);
        return sdf.format(date);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(new SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).format(date));
        dest.writeString(weather);
        dest.writeFloat(minTemp);
        dest.writeFloat(maxTemp);
        dest.writeInt(weatherIconRes);
        dest.writeString(windDir);
        dest.writeString(windScale);
        dest.writeInt(humidity);
    }
} 